/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div>
      <div class="fixed-bar">
        <div class="item-title">
          <router-link
            class="back"
            :to="{name: 'store_class_list', params:{currentPage:$route.params.currentPage}}"
            title="返回列表"
          >
            <i class="fa fa-arrow-circle-o-left"></i>
          </router-link>
          <div class="subject">
            <h3>
              店铺分类管理
              -
              <span v-if="scId">编辑</span>
              <span v-else>新增</span>店铺分类
            </h3>
            <h5>网站系统店铺分类管理</h5>
          </div>
        </div>
      </div>
      <el-form ref="form" :model="form" label-width="200px">
        <el-form-item label="分类名称">
          <el-input v-model="form.sc_name"></el-input>
          <p class="notic">设置店铺分类名称</p>
          <p class="err-msg" v-if="errResult.sc_name && !form.sc_name">{{errResult.sc_name}}</p>
        </el-form-item>
        <el-form-item label="保证金额度">
          <el-input v-model="form.sc_bail"></el-input>
          <p class="notic">0表示没有限制</p>
          <p class="err-msg" v-if="errResult.sc_bail && !form.sc_bail">{{errResult.sc_bail}}</p>
        </el-form-item>
        <el-form-item label="排序">
          <el-input v-model="form.sc_sort"></el-input>
          <p class="notic">数值越大表明前台列表排得越前</p>
          <p class="err-msg" v-if="errResult.sc_sort && !form.sc_sort">{{errResult.sc_sort}}</p>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" :loading="loading">确认提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  getStoreClassInfo,
  updateStoreClass,
  addStoreClass
} from "@/utils/api";
export default {
  data() {
    return {
      form: {},
      scId: this.$route.params.scId,
      loading: false,
      errResult: {}
    };
  },
  created() {
    if (this.$route.params.scId) {
      this.getStoreClass();
      console.log(this.form);
    }
  },
  methods: {
    getStoreClass() {
      var that = this;
      getStoreClassInfo({
        sc_id: that.scId
      }).then(function(res) {
        that.form = res;
      });
    },
    onSubmit() {
      this.loading = true;
      var that = this;
      if (this.form.sc_id) {
        //编辑
        updateStoreClass(that.form).then(function(res) {
          if (res.status == 1) {
            that.$message({
              message: "保存成功",
              type: "success",
              onClose: function() {
                that.$router.push({ name: "store_class_list" });
              }
            });
          } else if (res.status == -1) {
            that.$message.error("参数错误");
            that.errResult = res.result;
          } else {
            that.$message.error(res.msg);
          }
          that.loading = false;
        });
      } else {
        //添加
        addStoreClass(that.form).then(function(res) {
          if (res.status == 1) {
            that.$message({
              message: "添加成功",
              type: "success",
              onClose: function() {
                that.$router.push({ name: "store_class_list" });
              }
            });
          } else if (res.status == -1) {
            that.$message.error("参数错误");
            that.errResult = res.result;
          } else {
            that.$message.error(res.msg);
          }
          that.loading = false;
        });
      }
    }
  }
};
</script>

<style scoped>
</style>
